package org.myOrg.spetrum.GUI;

import org.myOrg.spetrum.io.InputManager;
import org.myOrg.spetrum.util.Message;
import org.myOrg.spetrum.util.MessageMangement;
import org.myOrg.spetrum.util.MessageMangementImplement;
import org.myOrg.spetrum.util.OverallFactory;
import org.myOrg.spetrum.util.Reciver;
import org.myOrg.spetrum.util.Transform;

public class ReadTestSuitePanel extends ShowPanel implements Reciver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ReadTestSuitePanel() {
		this.register(MessageMangementImplement.READOVER, OverallFactory
				.getMessageManger());
	}

	@Override
	public void handleMessage(Message msg) {
		// TODO Auto-generated method stub
		InputManager input = (InputManager) msg.getInfo();
		if (msg.getType() == MessageMangementImplement.READOVER) {
			this.clear();
			if (input.isFormatPass()) {
				this.insertOneLine("paramater:", StyleSet.getStyleTitle());
				this.insertOneLine(Transform.vectorToString(input.getParam()),
						StyleSet.getStyleNormal());

				this.insertOneLine("failed tests:", StyleSet.getStyleTitle());
				for (int i = 0; i < input.getWrongSuite().getTestCaseNum(); i++) {
					this.insertOneLine(input.getWrongSuite().getAt(i)
							.getStringOfTest(), StyleSet.getStyleFailed());
				}

				this.insertOneLine("passed tests:", StyleSet.getStyleTitle());
				for (int i = 0; i < input.getRightSuite().getTestCaseNum(); i++) {
					this.insertOneLine(input.getRightSuite().getAt(i)
							.getStringOfTest(), StyleSet.getStylePassed());
				}
				this.setLabelString("all:"
						+ input.getTestSuite().getTestCaseNum() + "  pass:"
						+ input.getRightSuite().getTestCaseNum() + "  fail:"
						+ input.getWrongSuite().getTestCaseNum());
			}
		}
	}

	@Override
	public void register(int messageType, MessageMangement messageManger) {
		// TODO Auto-generated method stub
		messageManger.register(this, messageType);
	}

}
